package com.gitee.zeric.codec.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

//import com.gitee.zeric.license.configuration.LicenseProperties;


/**
 * @author zj
 * @date 2021/12/17
 */
@Configuration
@ComponentScan("com.gitee.zeric.codec.service")
public class CodecAutoConfig {

    @ConditionalOnProperty(prefix = "codec.datasource.druid",name = "driver-class-name")
    @Primary
    @Bean
    @ConfigurationProperties(prefix = "codec.datasource.druid")
    public DataSourceProperties codecDataSourceProperties() {
        return new DataSourceProperties();
    }

    @ConditionalOnProperty(prefix = "codec.datasource.druid",name = "driver-class-name")
    @Primary
    @Bean
    public DataSource codecDataSource(@Qualifier("codecDataSourceProperties") DataSourceProperties dataSourceProperties) {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUsername(dataSourceProperties.getUsername());
        druidDataSource.setPassword(dataSourceProperties.getPassword());
        druidDataSource.setUrl(dataSourceProperties.getUrl());
        druidDataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
        return druidDataSource;
    }





}
